






















function WizardXmlBuilder()
{


this.AddColumn = addColumn;
this.AddGrouping = addGrouping;
this.ClearTableFilter = clearTableFilter;
this.GetAttributeAliases = getAttributeAliases;
this.GetColumn = getColumn;
this.GetColumnByAttributeAlias = getColumnByAttributeAlias;
this.GetColumnCount = getColumnCount;
this.GetColumns = getColumns;
this.GetColumnsWithSummaryValues = getColumnsWithSummaryValues;
this.GetColumnXml = getColumnXml;
this.GetGroupingCount = getGroupingCount;
this.GetGrouping = getGrouping;
this.GetGroupings = getGroupings;
this.GetGroupingXml = getGroupingXml;
this.GetTableFilterNode = getTableFilterNode;
this.GetTableIsDrillthrough = getTableIsDrillthrough;
this.GetTableLayoutXml = getTableLayoutXml;
this.GetTableWidth = getTableWidth;
this.MoveColumn = moveColumn;
this.MoveGrouping = moveGrouping;
this.RemoveColumn = removeColumn;
this.RemoveGrouping = removeGrouping;
this.SetColumnXml = setColumnXml;
this.SetGroupingXml = setGroupingXml;
this.SetTableLayoutXml = setTableLayoutXml;
this.SetTableFilter = setTableFilter;
this.SetTableIsDrillthrough = setTableIsDrillthrough;
this.UpdateColumn = updateColumn;
this.UpdateGrouping = updateGrouping;


var _oColumnXml = null;
var _oGroupingXml = null;
var _oTableLayoutXml = null;



function addAttributeAliases(saAliases, oaNodeList)
{
for (var i = 0; i < oaNodeList.length; i++)
saAliases.push(oaNodeList[i].getAttribute("Field"));
}

function addColumn(sAttributeAlias, sWidth, sSummaryValue, iPosition)
{

var sColumnId = createColumnId(sAttributeAlias);


var oColumnNode = _oColumnXml.createElement("Column");
oColumnNode.setAttribute("ID", sColumnId);
oColumnNode.setAttribute("Field", sAttributeAlias);
oColumnNode.setAttribute("Width", sWidth);
if (!IsNull(sSummaryValue) && sSummaryValue.length > 0)
{
oColumnNode.setAttribute("SummaryValue", sSummaryValue);
}


insertNode(oColumnNode, getColumnsRoot(), iPosition);


return sColumnId;
}

function addGrouping(sAttributeAlias, sSortOrder, sWidth, sTimeInterval, sSummaryValue, iPosition)
{

var oGroupingNode = _oGroupingXml.createElement("Grouping");
oGroupingNode.setAttribute("Field", sAttributeAlias);
oGroupingNode.setAttribute("Sort", sSortOrder);
oGroupingNode.setAttribute("Width", sWidth);
if (!IsNull(sTimeInterval) && sTimeInterval.length >0)
{
oGroupingNode.setAttribute("Interval", sTimeInterval);
}
if (!IsNull(sSummaryValue) && sSummaryValue.length > 0)
{
oGroupingNode.setAttribute("SummaryValue", sSummaryValue);
}


insertNode(oGroupingNode, getGroupingsRoot(), iPosition);
}

function clearTableFilter()
{

var oTableFilterNode = getTableFilterNode();
if (!IsNull(oTableFilterNode))
{
oTableFilterNode.parentNode.removeChild(oTableFilterNode);
}
}

function createColumnId(sAttributeAlias)
{
var iSuffix = 0;
var sColumnId = sAttributeAlias + iSuffix;
while (!IsNull(getColumn(sColumnId)))
{
iSuffix++;
sColumnId = sAttributeAlias + iSuffix;
}

return sColumnId;
}

function getAttributeAliases(iType)
{
var saAliases = new Array();
if (iType == PROPERTY_PAGE_TYPE_GROUP)
{
addAttributeAliases(saAliases, getGroupingsRoot().childNodes);
}
else
{
addAttributeAliases(saAliases, getColumnsRoot().childNodes);
}
return saAliases;
}

function getColumn(sColumnId)
{
return getColumnsRoot().selectSingleNode(formatString("*[@ID = '{0}']", sColumnId));
}

function getColumnByAttributeAlias(sAttributeAlias)
{
return getColumnsRoot().selectSingleNode(formatString("Column[@Field = '{0}']", sAttributeAlias));
}

function getColumnCount()
{
return getColumns().length;
}

function getColumns()
{
return getColumnsRoot().childNodes;
}

function getColumnsRoot()
{
return _oColumnXml.selectSingleNode("/Columns");
}

function getColumnsWithSummaryValues()
{
return getColumnsRoot().selectNodes("*[@SummaryValue]");
}

function getColumnXml()
{
return _oColumnXml;
}

function getDependencyCount(sAttributeAlias)
{
var iCount = 0;


var oaGroupingNodes = _oGroupingXml.selectNodes("/Groupings/Grouping");
for (var i = 0; i < oaGroupingNodes.length; i++)
{
if (oaGroupingNodes[i].getAttribute("Field") == sAttributeAlias)
{
iCount++;
}
}


var oaColumnNodes = _oColumnXml.selectNodes("/Columns/Column");
for (var i = 0; i < oaColumnNodes.length; i++)
{
if (oaColumnNodes[i].getAttribute("Field") == sAttributeAlias)
{
iCount++;
}
}

return iCount;
}

function getGrouping(sAttributeAlias)
{
return getGroupingsRoot().selectSingleNode(formatString("Grouping[@Field = '{0}']", sAttributeAlias));
}

function getGroupingCount()
{
return getGroupings().length;
}

function getGroupings()
{
return getGroupingsRoot().childNodes;
}

function getGroupingsRoot()
{
return _oGroupingXml.selectSingleNode("/Groupings");
}

function getGroupingXml()
{
return _oGroupingXml;
}

function getTableFilterNode()
{
return getTableLayoutRoot().selectSingleNode("Filter");
}

function getTableLayoutXml()
{
return _oTableLayoutXml;
}

function getPositionIndex(oNode, oaNodeList)
{
var iPosition = null;
for (var i = 0; i < oaNodeList.length && IsNull(iPosition); i++)
{
if (oaNodeList[i] == oNode)
{
iPosition = i;
}
}

return iPosition;
}

function getTableIsDrillthrough()
{
return (getTableLayoutRoot().getAttribute("Display") == "Drillthrough");
}

function getTableLayoutRoot()
{
return _oTableLayoutXml.selectSingleNode("/TableLayout");
}

function getTableWidth()
{
var iGroupingsWidth = getTotalWidth(getGroupings());
var iColumnsWidth = getTotalWidth(getColumns());
return (iGroupingsWidth + iColumnsWidth);
}

function getTotalWidth(oaNodes)
{
var iWidth = 0;
for (var i = 0; i < oaNodes.length; i++)
{
iWidth += parseInt(oaNodes[i].getAttribute("Width"), 10);
}
return iWidth;
}

function insertNode(oNode, oParentNode, iPosition)
{
if (IsNull(iPosition) || iPosition == oParentNode.childNodes.length)
{
oParentNode.appendChild(oNode);
}
else
{
oParentNode.insertBefore(oNode, oParentNode.childNodes[iPosition]);
}
}

function isTableFilterColumn(sColumnId)
{
var oFilterNode = getTableFilterNode();
return (!IsNull(oFilterNode) && oFilterNode.getAttribute("Column") == sColumnId);
}

function moveColumn(sColumnId, iDirection)
{

if (iDirection == DIRECTION_LEFT || iDirection == DIRECTION_RIGHT)
{
moveNode(getColumn(sColumnId), getColumnsRoot(), iDirection);
}
}

function moveGrouping(sAttributeAlias, iDirection)
{

if (iDirection == DIRECTION_UP || iDirection == DIRECTION_DOWN)
{
moveNode(getGrouping(sAttributeAlias), getGroupingsRoot(), iDirection);
}
}

function moveNode(oNode, oParentNode, iDirection)
{

var iPosition = getPositionIndex(oNode, oParentNode.childNodes);



var iNewPosition = null;
switch (iDirection)
{
case DIRECTION_UP:
case DIRECTION_LEFT:
iNewPosition = (iPosition == 0) ? iPosition : iPosition - 1;
break;
case DIRECTION_DOWN:
case DIRECTION_RIGHT:
iNewPosition = (iPosition == (oParentNode.childNodes.length - 1)) ? iPosition : iPosition + 1;
break;
}



if (IsNull(iNewPosition) || iNewPosition == iPosition)
{
return;
}


oParentNode.removeChild(oNode);
insertNode(oNode, oParentNode, iNewPosition);
}

function removeColumn(sColumnId)
{

var oColumn = getColumn(sColumnId);




var sAttributeAlias = oColumn.getAttribute("Field");


oColumn.parentNode.removeChild(oColumn);


if (isTableFilterColumn(sColumnId))
{
clearTableFilter();
}



return (getDependencyCount(sAttributeAlias) == 0);
}

function removeGrouping(sAttributeAlias)
{

var oGrouping = getGrouping(sAttributeAlias);


oGrouping.parentNode.removeChild(oGrouping);



if (getGroupingCount() == 0 && !IsNull(getTableFilterNode()))
{
clearTableFilter();
}



return (getDependencyCount(sAttributeAlias) == 0);
}

function setColumnXml(oColumnXml)
{
_oColumnXml = IsNull(oColumnXml) ? loadXmlDocument("<Columns />") : oColumnXml;
}

function setGroupingXml(oGroupingXml)
{
_oGroupingXml = IsNull(oGroupingXml) ? loadXmlDocument("<Groupings />") : oGroupingXml;
}

function setTableFilter(sColumnId, sFilterOperator, sFilterValue)
{

var oFilterNode = getTableFilterNode();
if (IsNull(oFilterNode))
{
oFilterNode = _oTableLayoutXml.createElement("Filter");
getTableLayoutRoot().appendChild(oFilterNode);
}


oFilterNode.setAttribute("Column", sColumnId);
oFilterNode.setAttribute("Operator", sFilterOperator);
oFilterNode.setAttribute("FilterValue", sFilterValue);
}

function setTableIsDrillthrough(bValue)
{
getTableLayoutRoot().setAttribute("Display", (bValue) ? "Drillthrough" : "Normal");
}

function setTableLayoutXml(oTableLayoutXml)
{
_oTableLayoutXml = IsNull(oTableLayoutXml) ? loadXmlDocument("<TableLayout Display=\"Normal\" />") : oTableLayoutXml;
}

function updateColumn(sColumnId, sWidth, sSummaryValue)
{

var oColumn = getColumn(sColumnId);


oColumn.setAttribute("Width", sWidth);
if (IsNull(sSummaryValue))
{
oColumn.removeAttribute("SummaryValue");



if (getGroupingCount() > 0 && isTableFilterColumn(sColumnId))
{
clearTableFilter();
}
}
else
{
oColumn.setAttribute("SummaryValue", sSummaryValue);
}
}

function updateGrouping(sAttributeAlias, sSortOrder, sWidth, sTimeInterval, sSummaryValue)
{

var oGrouping = getGrouping(sAttributeAlias);


oGrouping.setAttribute("Sort", sSortOrder);
oGrouping.setAttribute("Width", sWidth);
if (!IsNull(sTimeInterval))
{
oGrouping.setAttribute("Interval", sTimeInterval);
}
if (IsNull(sSummaryValue))
{
oGrouping.removeAttribute("SummaryValue");
}
else
{
oGrouping.setAttribute("SummaryValue", sSummaryValue);
}
}
}
